#pragma once
// MESSAGE GET_GENERAL_MESSAGE PACKING

#define TTALINK_MSG_ID_GET_GENERAL_MESSAGE 2241

TTAPACKED(
typedef struct __ttalink_get_general_message_t {
 uint8_t general_cmd; /*<  .*/
 uint8_t general_id; /*<  .*/
 int8_t general_name[10]; /*<  .*/
}) ttalink_get_general_message_t;

#define TTALINK_MSG_ID_GET_GENERAL_MESSAGE_LEN 12
#define TTALINK_MSG_ID_GET_GENERAL_MESSAGE_MIN_LEN 12
#define TTALINK_MSG_ID_2241_LEN 12
#define TTALINK_MSG_ID_2241_MIN_LEN 12

#define TTALINK_MSG_ID_GET_GENERAL_MESSAGE_CRC 135
#define TTALINK_MSG_ID_2241_CRC 135

#define TTALINK_MSG_GET_GENERAL_MESSAGE_FIELD_GENERAL_NAME_LEN 10

#if TTALINK_COMMAND_24BIT
#define TTALINK_MESSAGE_INFO_GET_GENERAL_MESSAGE { \
    2241, \
    "GET_GENERAL_MESSAGE", \
    3, \
    {  { "general_cmd", NULL, TTALINK_TYPE_UINT8_T, 0, 0, offsetof(ttalink_get_general_message_t, general_cmd) }, \
         { "general_id", NULL, TTALINK_TYPE_UINT8_T, 0, 1, offsetof(ttalink_get_general_message_t, general_id) }, \
         { "general_name", NULL, TTALINK_TYPE_INT8_T, 10, 2, offsetof(ttalink_get_general_message_t, general_name) }, \
         } \
}
#else
#define TTALINK_MESSAGE_INFO_GET_GENERAL_MESSAGE { \
    "GET_GENERAL_MESSAGE", \
    3, \
    {  { "general_cmd", NULL, TTALINK_TYPE_UINT8_T, 0, 0, offsetof(ttalink_get_general_message_t, general_cmd) }, \
         { "general_id", NULL, TTALINK_TYPE_UINT8_T, 0, 1, offsetof(ttalink_get_general_message_t, general_id) }, \
         { "general_name", NULL, TTALINK_TYPE_INT8_T, 10, 2, offsetof(ttalink_get_general_message_t, general_name) }, \
         } \
}
#endif


static inline uint16_t _ttalink_get_general_message_pack(uint8_t dst_addr, uint8_t src_addr, ttalink_message_t* msg,
                               uint8_t general_cmd, uint8_t general_id, const int8_t *general_name, bool nocrc)
{
#if TTALINK_NEED_BYTE_SWAP || !TTALINK_ALIGNED_FIELDS
    char buf[TTALINK_MSG_ID_GET_GENERAL_MESSAGE_LEN];
    _tta_put_uint8_t(buf, 0, general_cmd);
    _tta_put_uint8_t(buf, 1, general_id);
    _tta_put_int8_t_array(buf, 2, general_name, 10);
        memcpy(_TTA_PAYLOAD_NON_CONST(msg), buf, TTALINK_MSG_ID_GET_GENERAL_MESSAGE_LEN);
#else
    ttalink_get_general_message_t packet;
    packet.general_cmd = general_cmd;
    packet.general_id = general_id;
    tta_array_memcpy(packet.general_name, general_name, sizeof(int8_t)*10);
        memcpy(_TTA_PAYLOAD_NON_CONST(msg), &packet, TTALINK_MSG_ID_GET_GENERAL_MESSAGE_LEN);
#endif

    msg->msgid = TTALINK_MSG_ID_GET_GENERAL_MESSAGE;
    return ttalink_finalize_message(msg, dst_addr, src_addr, TTALINK_MSG_ID_GET_GENERAL_MESSAGE_MIN_LEN, TTALINK_MSG_ID_GET_GENERAL_MESSAGE_LEN, TTALINK_MSG_ID_GET_GENERAL_MESSAGE_CRC, nocrc);
}

/**
 * @brief Pack a get_general_message message
 * @param dst_addr 
 * @param src_addr
 * @param msg The TTAlink message to compress the data into
 *
 * @param general_cmd  .
 * @param general_id  .
 * @param general_name  .
 * @return length of the message in bytes (excluding serial stream start sign)
 */
static inline uint16_t ttalink_get_general_message_pack(uint8_t dst_addr, uint8_t src_addr, ttalink_message_t* msg,
                               uint8_t general_cmd, uint8_t general_id, const int8_t *general_name)
{
    return _ttalink_get_general_message_pack(dst_addr, src_addr, msg,  general_cmd, general_id, general_name, false);
}

/**
 * @brief Pack a get_general_message message, no crc
 * @param dst_addr 
 * @param src_addr
 * @param msg The TTAlink message to compress the data into
 *
 * @param general_cmd  .
 * @param general_id  .
 * @param general_name  .
 * @return length of the message in bytes (excluding serial stream start sign)
 */
static inline uint16_t ttalink_get_general_message_pack_nocrc(uint8_t dst_addr, uint8_t src_addr, ttalink_message_t* msg,
                               uint8_t general_cmd, uint8_t general_id, const int8_t *general_name)
{
    return _ttalink_get_general_message_pack(dst_addr, src_addr, msg,  general_cmd, general_id, general_name, true);
}


static inline uint16_t _ttalink_get_general_message_pack_chan(uint8_t dst_addr, uint8_t src_addr, ttalink_channel_t chan,
                               ttalink_message_t* msg,
                                   uint8_t general_cmd,uint8_t general_id,const int8_t *general_name, bool nocrc)
{
#if TTALINK_NEED_BYTE_SWAP || !TTALINK_ALIGNED_FIELDS
    char buf[TTALINK_MSG_ID_GET_GENERAL_MESSAGE_LEN];
    _tta_put_uint8_t(buf, 0, general_cmd);
    _tta_put_uint8_t(buf, 1, general_id);
    _tta_put_int8_t_array(buf, 2, general_name, 10);
        memcpy(_TTA_PAYLOAD_NON_CONST(msg), buf, TTALINK_MSG_ID_GET_GENERAL_MESSAGE_LEN);
#else
    ttalink_get_general_message_t packet;
    packet.general_cmd = general_cmd;
    packet.general_id = general_id;
    tta_array_memcpy(packet.general_name, general_name, sizeof(int8_t)*10);
        memcpy(_TTA_PAYLOAD_NON_CONST(msg), &packet, TTALINK_MSG_ID_GET_GENERAL_MESSAGE_LEN);
#endif

    msg->msgid = TTALINK_MSG_ID_GET_GENERAL_MESSAGE;
    return ttalink_finalize_message_chan(msg, dst_addr, src_addr, chan, TTALINK_MSG_ID_GET_GENERAL_MESSAGE_MIN_LEN, TTALINK_MSG_ID_GET_GENERAL_MESSAGE_LEN, TTALINK_MSG_ID_GET_GENERAL_MESSAGE_CRC, nocrc);
}

/**
 * @brief Pack a get_general_message message on a channel
 * @param dst_addr ID of this system
 * @param src_addr ID of this component (e.g. 200 for IMU)
 * @param chan The TTAlink channel this message will be sent over
 * @param msg The TTAlink message to compress the data into
 * @param general_cmd  .
 * @param general_id  .
 * @param general_name  .
 * @return length of the message in bytes (excluding serial stream start sign)
 */
static inline uint16_t ttalink_get_general_message_pack_chan(uint8_t dst_addr, uint8_t src_addr, ttalink_channel_t chan,
                               ttalink_message_t* msg,
                                   uint8_t general_cmd,uint8_t general_id,const int8_t *general_name)
{
    return _ttalink_get_general_message_pack_chan(dst_addr, src_addr, chan, msg,  general_cmd, general_id, general_name, false);
}

/**
 * @brief Pack a get_general_message message on a channel, no crc
 * @param dst_addr ID of this system
 * @param src_addr ID of this component (e.g. 200 for IMU)
 * @param chan The TTAlink channel this message will be sent over
 * @param msg The TTAlink message to compress the data into
 * @param general_cmd  .
 * @param general_id  .
 * @param general_name  .
 * @return length of the message in bytes (excluding serial stream start sign)
 */
static inline uint16_t ttalink_get_general_message_pack_chan_nocrc(uint8_t dst_addr, uint8_t src_addr, ttalink_channel_t chan,
                               ttalink_message_t* msg,
                                   uint8_t general_cmd,uint8_t general_id,const int8_t *general_name)
{
    return _ttalink_get_general_message_pack_chan(dst_addr, src_addr, chan, msg,  general_cmd, general_id, general_name, true);
}


static inline uint16_t _ttalink_get_general_message_encode(uint8_t dst_addr, uint8_t src_addr, ttalink_message_t* msg, const ttalink_get_general_message_t* get_general_message, bool nocrc)
{
    if(nocrc){
        return ttalink_get_general_message_pack_nocrc(dst_addr, src_addr, msg, get_general_message->general_cmd, get_general_message->general_id, get_general_message->general_name);
    }else{
        return ttalink_get_general_message_pack(dst_addr, src_addr, msg, get_general_message->general_cmd, get_general_message->general_id, get_general_message->general_name);
    }
    
}

/**
 * @brief Encode a get_general_message struct
 *
 * @param dst_addr ID of this system
 * @param src_addr ID of this component (e.g. 200 for IMU)
 * @param msg The TTAlink message to compress the data into
 * @param get_general_message C-struct to read the message contents from
 */
static inline uint16_t ttalink_get_general_message_encode(uint8_t dst_addr, uint8_t src_addr, ttalink_message_t* msg, const ttalink_get_general_message_t* get_general_message)
{
    return _ttalink_get_general_message_encode(dst_addr, src_addr, msg, get_general_message, false);
}

/**
 * @brief Encode a get_general_message struct, no crc
 *
 * @param dst_addr ID of this system
 * @param src_addr ID of this component (e.g. 200 for IMU)
 * @param msg The TTAlink message to compress the data into
 * @param get_general_message C-struct to read the message contents from
 */
static inline uint16_t ttalink_get_general_message_encode_nocrc(uint8_t dst_addr, uint8_t src_addr, ttalink_message_t* msg, const ttalink_get_general_message_t* get_general_message)
{
    return _ttalink_get_general_message_encode(dst_addr, src_addr, msg, get_general_message, true);
}


static inline uint16_t _ttalink_get_general_message_encode_chan(uint8_t dst_addr, uint8_t src_addr, ttalink_channel_t chan, ttalink_message_t* msg, const ttalink_get_general_message_t* get_general_message, bool nocrc)
{
    if(nocrc){
        return ttalink_get_general_message_pack_chan_nocrc(dst_addr, src_addr, chan, msg, get_general_message->general_cmd, get_general_message->general_id, get_general_message->general_name);
    }else{
        return ttalink_get_general_message_pack_chan(dst_addr, src_addr, chan, msg, get_general_message->general_cmd, get_general_message->general_id, get_general_message->general_name);
    }
}

/**
 * @brief Encode a get_general_message struct on a channel
 *
 * @param dst_addr ID of this system
 * @param src_addr ID of this component (e.g. 200 for IMU)
 * @param chan The TTAlink channel this message will be sent over
 * @param msg The TTAlink message to compress the data into
 * @param get_general_message C-struct to read the message contents from
 */
static inline uint16_t ttalink_get_general_message_encode_chan(uint8_t dst_addr, uint8_t src_addr, ttalink_channel_t chan, ttalink_message_t* msg, const ttalink_get_general_message_t* get_general_message)
{
    return _ttalink_get_general_message_encode_chan(dst_addr, src_addr, chan, msg, get_general_message, false);
}

/**
 * @brief Encode a get_general_message struct on a channel, no crc
 *
 * @param dst_addr ID of this system
 * @param src_addr ID of this component (e.g. 200 for IMU)
 * @param chan The TTAlink channel this message will be sent over
 * @param msg The TTAlink message to compress the data into
 * @param get_general_message C-struct to read the message contents from
 */
static inline uint16_t ttalink_get_general_message_encode_chan_nocrc(uint8_t dst_addr, uint8_t src_addr, ttalink_channel_t chan, ttalink_message_t* msg, const ttalink_get_general_message_t* get_general_message)
{
    return _ttalink_get_general_message_encode_chan(dst_addr, src_addr, chan, msg, get_general_message, true);
}


#ifdef TTALINK_USE_CONVENIENCE_FUNCTIONS

static inline void _ttalink_get_general_message_send(uint8_t dst_addr, uint8_t src_addr, ttalink_channel_t chan, uint8_t general_cmd, uint8_t general_id, const int8_t *general_name, bool nocrc)
{
#if TTALINK_NEED_BYTE_SWAP || !TTALINK_ALIGNED_FIELDS
    char buf[TTALINK_MSG_ID_GET_GENERAL_MESSAGE_LEN];
    _tta_put_uint8_t(buf, 0, general_cmd);
    _tta_put_uint8_t(buf, 1, general_id);
    _tta_put_int8_t_array(buf, 2, general_name, 10);
    _tta_finalize_message_chan_send(dst_addr, src_addr, chan, TTALINK_MSG_ID_GET_GENERAL_MESSAGE, buf, TTALINK_MSG_ID_GET_GENERAL_MESSAGE_MIN_LEN, TTALINK_MSG_ID_GET_GENERAL_MESSAGE_LEN, TTALINK_MSG_ID_GET_GENERAL_MESSAGE_CRC, nocrc);
#else
    ttalink_get_general_message_t packet;
    packet.general_cmd = general_cmd;
    packet.general_id = general_id;
    tta_array_memcpy(packet.general_name, general_name, sizeof(int8_t)*10);
    _tta_finalize_message_chan_send(dst_addr, src_addr, chan, TTALINK_MSG_ID_GET_GENERAL_MESSAGE, (const char *)&packet, TTALINK_MSG_ID_GET_GENERAL_MESSAGE_MIN_LEN, TTALINK_MSG_ID_GET_GENERAL_MESSAGE_LEN, TTALINK_MSG_ID_GET_GENERAL_MESSAGE_CRC, nocrc);
#endif
}

/**
 * @brief Send a get_general_message message
 * @param chan TTAlink channel to send the message
 *
 * @param general_cmd  .
 * @param general_id  .
 * @param general_name  .
 */
static inline void ttalink_get_general_message_send(uint8_t dst_addr, uint8_t src_addr, ttalink_channel_t chan, uint8_t general_cmd, uint8_t general_id, const int8_t *general_name)
{
    _ttalink_get_general_message_send(dst_addr, src_addr, chan, general_cmd, general_id, general_name, false);
}

/**
 * @brief Send a get_general_message message, no crc
 * @param chan TTAlink channel to send the message
 *
 * @param general_cmd  .
 * @param general_id  .
 * @param general_name  .
 */
static inline void ttalink_get_general_message_send_nocrc(uint8_t dst_addr, uint8_t src_addr, ttalink_channel_t chan, uint8_t general_cmd, uint8_t general_id, const int8_t *general_name)
{
    _ttalink_get_general_message_send(dst_addr, src_addr, chan, general_cmd, general_id, general_name, true);
}


static inline void _ttalink_get_general_message_send_struct(uint8_t dst_addr, uint8_t src_addr, ttalink_channel_t chan, const ttalink_get_general_message_t* get_general_message, bool nocrc)
{
#if TTALINK_NEED_BYTE_SWAP || !TTALINK_ALIGNED_FIELDS
    if(nocrc){
        ttalink_get_general_message_send_nocrc(dst_addr, src_addr, chan, get_general_message->general_cmd, get_general_message->general_id, get_general_message->general_name);
    }else{
        ttalink_get_general_message_send(dst_addr, src_addr, chan, get_general_message->general_cmd, get_general_message->general_id, get_general_message->general_name);
    }
#else
    _tta_finalize_message_chan_send(dst_addr, src_addr, chan, TTALINK_MSG_ID_GET_GENERAL_MESSAGE, (const char *)get_general_message, TTALINK_MSG_ID_GET_GENERAL_MESSAGE_MIN_LEN, TTALINK_MSG_ID_GET_GENERAL_MESSAGE_LEN, TTALINK_MSG_ID_GET_GENERAL_MESSAGE_CRC, nocrc);
#endif
}

/**
 * @brief Send a get_general_message message
 * @param chan TTAlink channel to send the message
 * @param struct The TTAlink struct to serialize
 */
static inline void ttalink_get_general_message_send_struct(uint8_t dst_addr, uint8_t src_addr, ttalink_channel_t chan, const ttalink_get_general_message_t* get_general_message)
{
    _ttalink_get_general_message_send_struct(dst_addr, src_addr, chan, get_general_message, false);
}

/**
 * @brief Send a get_general_message message, no crc
 * @param chan TTAlink channel to send the message
 * @param struct The TTAlink struct to serialize
 */
static inline void ttalink_get_general_message_send_struct_nocrc(uint8_t dst_addr, uint8_t src_addr, ttalink_channel_t chan, const ttalink_get_general_message_t* get_general_message)
{
    _ttalink_get_general_message_send_struct(dst_addr, src_addr, chan, get_general_message, true);
}

#if TTALINK_MSG_ID_GET_GENERAL_MESSAGE_LEN <= TTALINK_MAX_PAYLOAD_LEN
static inline void _ttalink_get_general_message_send_buf(uint8_t dst_addr, uint8_t src_addr, ttalink_message_t *msgbuf, ttalink_channel_t chan,  uint8_t general_cmd, uint8_t general_id, const int8_t *general_name, bool nocrc)
{
#if TTALINK_NEED_BYTE_SWAP || !TTALINK_ALIGNED_FIELDS
    char *buf = (char *)msgbuf;
    _tta_put_uint8_t(buf, 0, general_cmd);
    _tta_put_uint8_t(buf, 1, general_id);
    _tta_put_int8_t_array(buf, 2, general_name, 10);
    _tta_finalize_message_chan_send(dst_addr, src_addr, chan, TTALINK_MSG_ID_GET_GENERAL_MESSAGE, buf, TTALINK_MSG_ID_GET_GENERAL_MESSAGE_MIN_LEN, TTALINK_MSG_ID_GET_GENERAL_MESSAGE_LEN, TTALINK_MSG_ID_GET_GENERAL_MESSAGE_CRC, nocrc);
#else
    ttalink_get_general_message_t *packet = (ttalink_get_general_message_t *)msgbuf;
    packet->general_cmd = general_cmd;
    packet->general_id = general_id;
    tta_array_memcpy(packet->general_name, general_name, sizeof(int8_t)*10);
    _tta_finalize_message_chan_send(dst_addr, src_addr, chan, TTALINK_MSG_ID_GET_GENERAL_MESSAGE, (const char *)packet, TTALINK_MSG_ID_GET_GENERAL_MESSAGE_MIN_LEN, TTALINK_MSG_ID_GET_GENERAL_MESSAGE_LEN, TTALINK_MSG_ID_GET_GENERAL_MESSAGE_CRC, nocrc);
#endif
}

/*
  This varient of _send() can be used to save stack space by re-using
  memory from the receive buffer.  The caller provides a
  ttalink_message_t which is the size of a full ttalink message. This
  is usually the receive buffer for the channel, and allows a reply to an
  incoming message with minimum stack space usage.
 */
static inline void ttalink_get_general_message_send_buf(uint8_t dst_addr, uint8_t src_addr, ttalink_message_t *msgbuf, ttalink_channel_t chan,  uint8_t general_cmd, uint8_t general_id, const int8_t *general_name)
{
    _ttalink_get_general_message_send_buf(dst_addr, src_addr, msgbuf, chan, general_cmd, general_id, general_name, false);
}

/*
  This varient of _send() can be used to save stack space by re-using
  memory from the receive buffer.  The caller provides a
  ttalink_message_t which is the size of a full ttalink message. This
  is usually the receive buffer for the channel, and allows a reply to an
  incoming message with minimum stack space usage, no crc.
 */
static inline void ttalink_get_general_message_send_buf_nocrc(uint8_t dst_addr, uint8_t src_addr, ttalink_message_t *msgbuf, ttalink_channel_t chan,  uint8_t general_cmd, uint8_t general_id, const int8_t *general_name)
{
    _ttalink_get_general_message_send_buf(dst_addr, src_addr, msgbuf, chan, general_cmd, general_id, general_name, true);
}
#endif

#endif

// MESSAGE GET_GENERAL_MESSAGE UNPACKING


/**
 * @brief Get field general_cmd from get_general_message message
 *
 * @return  .
 */
static inline uint8_t ttalink_get_general_message_get_general_cmd(const ttalink_message_t* msg)
{
    return _TTA_RETURN_uint8_t(msg,  0);
}

/**
 * @brief Get field general_id from get_general_message message
 *
 * @return  .
 */
static inline uint8_t ttalink_get_general_message_get_general_id(const ttalink_message_t* msg)
{
    return _TTA_RETURN_uint8_t(msg,  1);
}

/**
 * @brief Get field general_name from get_general_message message
 *
 * @return  .
 */
static inline uint16_t ttalink_get_general_message_get_general_name(const ttalink_message_t* msg, int8_t *general_name)
{
    return _TTA_RETURN_int8_t_array(msg, general_name, 10,  2);
}

/**
 * @brief Decode a get_general_message message into a struct
 *
 * @param msg The message to decode
 * @param get_general_message C-struct to decode the message contents into
 */
static inline void ttalink_get_general_message_decode(const ttalink_message_t* msg, ttalink_get_general_message_t* get_general_message)
{
#if TTALINK_NEED_BYTE_SWAP || !TTALINK_ALIGNED_FIELDS
    get_general_message->general_cmd = ttalink_get_general_message_get_general_cmd(msg);
    get_general_message->general_id = ttalink_get_general_message_get_general_id(msg);
    ttalink_get_general_message_get_general_name(msg, get_general_message->general_name);
#else
        uint8_t len = msg->len < TTALINK_MSG_ID_GET_GENERAL_MESSAGE_LEN? msg->len : TTALINK_MSG_ID_GET_GENERAL_MESSAGE_LEN;
        memset(get_general_message, 0, TTALINK_MSG_ID_GET_GENERAL_MESSAGE_LEN);
    memcpy(get_general_message, _TTA_PAYLOAD(msg), len);
#endif
}
